package com.jeethink.erp.type.controller;

import java.util.List;

import com.jeethink.common.core.domain.entity.TbShop;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.jeethink.common.annotation.Log;
import com.jeethink.common.core.controller.BaseController;
import com.jeethink.common.core.domain.AjaxResult;
import com.jeethink.common.enums.BusinessType;
import com.jeethink.common.core.domain.entity.TbCommodityType;
import com.jeethink.erp.type.service.ITbCommodityTypeService;
import com.jeethink.common.utils.poi.ExcelUtil;
import com.jeethink.common.core.page.TableDataInfo;

/**
 * 商品类型Controller
 * 
 * @author ypr
 * @date 2021-06-09
 */
@RestController
@RequestMapping("/erp/type")
public class TbCommodityTypeController extends BaseController
{
    @Autowired
    private ITbCommodityTypeService tbCommodityTypeService;

    /**
     * 查询商品类型列表
     */
    @GetMapping("/list")
    public AjaxResult list(TbCommodityType tbCommodityType)
    {
        List<TbCommodityType> list = tbCommodityTypeService.selectTbCommodityTypeList(tbCommodityType);
        return AjaxResult.success(list);

    }

    /**
     * 导出商品类型列表
     */
    @PreAuthorize("@ss.hasPermi('erp:type:export')")
    @Log(title = "商品类型", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(TbCommodityType tbCommodityType)
    {
        List<TbCommodityType> list = tbCommodityTypeService.selectTbCommodityTypeList(tbCommodityType);
        ExcelUtil<TbCommodityType> util = new ExcelUtil<TbCommodityType>(TbCommodityType.class);
        return util.exportExcel(list, "type");
    }

    /**
     * 获取商品类型详细信息
     */
    @PreAuthorize("@ss.hasPermi('erp:type:query')")
    @GetMapping(value = "/{commodityTypeId}")
    public AjaxResult getInfo(@PathVariable("commodityTypeId") Long commodityTypeId)
    {
        return AjaxResult.success(tbCommodityTypeService.selectTbCommodityTypeById(commodityTypeId));
    }

    /**
     * 新增商品类型
     */
    @PreAuthorize("@ss.hasPermi('erp:type:add')")
    @Log(title = "商品类型", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TbCommodityType tbCommodityType)
    {
        return toAjax(tbCommodityTypeService.insertTbCommodityType(tbCommodityType));
    }

    /**
     * 修改商品类型
     */
    @PreAuthorize("@ss.hasPermi('erp:type:edit')")
    @Log(title = "商品类型", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TbCommodityType tbCommodityType)
    {
        return toAjax(tbCommodityTypeService.updateTbCommodityType(tbCommodityType));
    }

    /**
     * 删除商品类型
     */
    @PreAuthorize("@ss.hasPermi('erp:type:remove')")
    @Log(title = "商品类型", businessType = BusinessType.DELETE)
	@DeleteMapping("/{commodityTypeIds}")
    public AjaxResult remove(@PathVariable Long[] commodityTypeIds)
    {
        return toAjax(tbCommodityTypeService.deleteTbCommodityTypeByIds(commodityTypeIds));
    }


    /**
     * 获取商品类型下拉树列表
     */
    @GetMapping("/treeselect")
    public AjaxResult treeselect(TbCommodityType tbCommodityType)
    {
        List<TbCommodityType> list = tbCommodityTypeService.selectTbCommodityTypeList(tbCommodityType);
        return AjaxResult.success(tbCommodityTypeService.buildShopTreeSelect(list));
    }
}
